home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / OpenGL 1.0 SDK / Source / Examples / aux / samples / accum.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-18  |  2.4 KB  |  133 lines  |  [TEXT/CWIE]

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <unistd.h>
  4. #include <stdlib.h>
  5. #include "tk.h"
  6.  
  7.  
  8. GLenum doubleBuffer, directRender;
  9. GLint thing1, thing2;
  10.  
  11.  
  12. static void Init(void)
  13. {
  14.  
  15.     glClearColor(0.0, 0.0, 0.0, 0.0);
  16.     glClearAccum(0.0, 0.0, 0.0, 0.0);
  17.  
  18.     thing1 = glGenLists(1);
  19.     glNewList(thing1, GL_COMPILE);
  20.     glColor3f(1.0, 0.0, 0.0);
  21.     glRectf(-1.0, -1.0, 1.0, 0.0);
  22.     glEndList();
  23.  
  24.     thing2 = glGenLists(1);
  25.     glNewList(thing2, GL_COMPILE);
  26.     glColor3f(0.0, 1.0, 0.0);
  27.     glRectf(0.0, -1.0, 1.0, 1.0);
  28.     glEndList();
  29. }
  30.  
  31. static void Reshape(int width, int height)
  32. {
  33.  
  34.     glViewport(0, 0, (GLint)width, (GLint)height);
  35.  
  36.     glMatrixMode(GL_PROJECTION);
  37.     glLoadIdentity();
  38.     glMatrixMode(GL_MODELVIEW);
  39.     glLoadIdentity();
  40. }
  41.  
  42. static GLenum Key(int key, GLenum mask)
  43. {
  44.  
  45.     switch (key) {
  46.       case TK_ESCAPE:
  47.     tkQuit();
  48.       case TK_1:
  49.     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  50.     break;
  51.       case TK_2:
  52.     glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  53.     break;
  54.       default:
  55.     return GL_FALSE;
  56.     }
  57.     return GL_TRUE;
  58. }
  59.  
  60. static void Draw(void)
  61. {
  62.  
  63.     glPushMatrix();
  64.  
  65.     glScalef(0.8, 0.8, 1.0);
  66.  
  67.     glClear(GL_COLOR_BUFFER_BIT);
  68.     glCallList(thing1);
  69.     glAccum(GL_LOAD, 0.5);
  70.  
  71.     glClear(GL_COLOR_BUFFER_BIT);
  72.     glCallList(thing2);
  73.     glAccum(GL_ACCUM, 0.5);
  74.  
  75.     glAccum(GL_RETURN, 1.0);
  76.  
  77.     glPopMatrix();
  78.  
  79.     glFlush();
  80. }
  81.  
  82. static GLenum Args(int argc, char **argv)
  83. {
  84.     GLint i;
  85.  
  86.     doubleBuffer = GL_FALSE;
  87.     directRender = GL_TRUE;
  88.  
  89.     for (i = 1; i < argc; i++) {
  90.     if (strcmp(argv[i], "-sb") == 0) {
  91.         doubleBuffer = GL_FALSE;
  92.     } else if (strcmp(argv[i], "-db") == 0) {
  93.         doubleBuffer = GL_TRUE;
  94.     } else if (strcmp(argv[i], "-dr") == 0) {
  95.         directRender = GL_TRUE;
  96.     } else if (strcmp(argv[i], "-ir") == 0) {
  97.         directRender = GL_FALSE;
  98.     } else {
  99.         printf("%s (Bad option).\n", argv[i]);
  100.         return GL_FALSE;
  101.     }
  102.     }
  103.     return GL_TRUE;
  104. }
  105.  
  106. void main(int argc, char **argv)
  107. {
  108.     GLenum type;
  109.  
  110.     if (Args(argc, argv) == GL_FALSE) {
  111.         tkQuit();
  112.     }
  113.  
  114.     tkInitPosition(30, 60, 300, 300);
  115.  
  116.     type = TK_RGB | TK_ACCUM;
  117.     type |= (doubleBuffer) ? TK_DOUBLE : TK_SINGLE;
  118.     type |= (directRender) ? TK_DIRECT : TK_INDIRECT;
  119.     tkInitDisplayMode(type);
  120.  
  121.     if (tkInitWindow("Accum Test") == GL_FALSE) {
  122.     tkQuit();
  123.     }
  124.  
  125.     Init();
  126.  
  127.     tkExposeFunc(Reshape);
  128.     tkReshapeFunc(Reshape);
  129.     tkKeyDownFunc(Key);
  130.     tkDisplayFunc(Draw);
  131.     tkExec();
  132. }
  133.